﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algobox.JuicyLib.Apps.EODData.Files
{
    public class Names : Dictionary<string, string>
    {
        public Names(ref string file)
        {
            LoadFile(ref file);
        }

        public const string FILENAME_LSE = "ftp://ftp.eoddata.com/Names/LSE.txt";
        public const string FILENAME_MLSE = "ftp://ftp.eoddata.com/Names/MLSE.txt";
        public const string FILENAME_FOREX = "ftp://ftp.eoddata.com/Names/FOREX.txt";
        public const string FILENAME_NYSE = "ftp://ftp.eoddata.com/Names/NYSE.txt";
        public const string FILENAME_NASDAQ = "ftp://ftp.eoddata.com/Names/NASDAQ.txt";
        public const string FILENAME_AMEX = "ftp://ftp.eoddata.com/Names/AMEX.txt";
        public const string FILENAME_TSX = "ftp://ftp.eoddata.com/Names/TSX.txt";
        public const string FILENAME_TSXV = "ftp://ftp.eoddata.com/Names/TSXV.txt";

        const char NAME_SEPERATOR = '\t';
        const int NAME_COLUMNS = 2;

        const int NAME_SYMBOL = 0;
        const int NAME_NAME = 1;

        void LoadFile(ref string file)
        {
            try
            {
                string[] elements; 
                string[] lines = file.Substring(file.IndexOf('\n')).Split('\n');
                foreach (string line in lines)
                {
                    elements = line.Split(NAME_SEPERATOR);

                    if (elements.Length != NAME_COLUMNS)
                        continue;

                    // save this ohlc element
                    this.Add(elements[NAME_SYMBOL], elements[NAME_NAME]);
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e);
            }
        }



    }
}
